package com.activenetwork.smlite.testcase.daily;

import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.activenetwork.schema.testcase.daily.checkeventpart.CheckEventPartDataType;
import com.activenetwork.smlite.business.EventBusiness;
import com.activenetwork.smlite.page.generic.ModelPage;
import com.activenetwork.smlite.testcase.BaseCase;
import com.activenetwork.util.EnvContext;
import com.activenetwork.util.PageLoader;
import com.activenetwork.util.jaxb.ScriptDataBindHelper;
import com.activenetwork.util.verification.gson.FailureAssertion;
import com.activenetwork.util.verification.gson.FailurePoint;

public class CheckEventPart extends BaseCase {
	static final Logger logger = LoggerFactory.getLogger(CheckEventPart.class);
	private EventBusiness eventBusiness = new EventBusiness();
	private CheckEventPartDataType data;
	
	@BeforeClass(alwaysRun = true)
	public void dataSetup() {	
		try{
			ScriptDataBindHelper helper = new ScriptDataBindHelper(CheckEventPart.class);
			data = helper.bind(CheckEventPartDataType.class);
		}catch(IOException e){
			throw new RuntimeException("Unable to bind the script data for " + this.getClass().getName());
		}
	}
	
	@BeforeClass(alwaysRun = true, dependsOnMethods = {"dataSetup"})
	public void login(){
		loginBusiness.login();
	}
	
	@Test(groups = { "daily" })
	public void createMultiDayEvent(){
		logger.info("createMultiDayEvent method");
		eventBusiness.addEventUI(data.getMultiDayEvent());
	}
	
	@Test(groups = { "daily" })
	public void createSingleDayEvent(){
		logger.info("createSinleDayEvent method");
		eventBusiness.addEventUI(data.getSingleDayEvent());
	}
	
	@Test(groups = { "daily" }, dependsOnMethods = {"createMultiDayEvent"})
	public void deleteMultiDayEvent(){
		logger.info("deleteMultiDayEvent method");
		ModelPage modelpage = PageLoader.load(ModelPage.class);
		modelpage.events();
		String searchContext = data.getMultiDayEvent().getBasic().getTitle();
		try{
			eventBusiness.deleteEvent(searchContext, data.getMultiDayEvent());
		}catch(RuntimeException e){
			EnvContext.failurePointTL.get().add(new FailurePoint(
					CheckEventPart.class.getName(), 
					"Verify delete daily run multiple days event", 
					"Unable to delete this event"));
		}
	}
	
	@Test(groups = { "daily" }, dependsOnMethods = {"createSingleDayEvent"})
	public void deleteSingleDayEvent(){
		logger.info("deleteSinleDayEvent method");
		logger.info("deleteMultiDayEvent method");
		ModelPage modelpage = PageLoader.load(ModelPage.class);
		modelpage.events();
		String searchContext = data.getSingleDayEvent().getBasic().getTitle();
		try{
			eventBusiness.deleteEvent(searchContext, data.getSingleDayEvent());
		}catch(RuntimeException e){
			EnvContext.failurePointTL.get().add(new FailurePoint(
					CheckEventPart.class.getName(), 
					"Verify delete daily run sinle day event", 
					"Unable to delete this event"));
		}
	}
	
	@AfterClass
	public void logoff(){
		loginBusiness.logout();
		FailureAssertion.pop(CheckEventPart.class);
	}
	
}
